package oaSystem.biz.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import oaSystem.biz.DepartmentBiz;
import oaSystem.entity.Department;
import oaSystem.mapper.DepartmentMapper;
import oaSystem.mapper.EmployeeMapper;
@Service
public class DepartmentBizImpl implements DepartmentBiz {
	
	@Autowired
	private DepartmentMapper departmentMapper;
	@Autowired
	private EmployeeMapper employeeMapper;
	
	@Override
	public void addDepartment(Department department) {
		departmentMapper.addDepartment(department);
	}

	@Override
	public void updaDepartment(Department department) {
		departmentMapper.updateDepartment(department);
	}
	@Override
	public void logOutDepartment(Integer departmentId){//0-注销 1-存在 2-暂停
		Department department = departmentMapper.fetchDepartmentById(departmentId);
		department.setStatus(0);
		updaDepartment( department);
	}
	@Override
	public List<Department> findAllDepartment() {
		List<Department> departments = departmentMapper.findAllDepartment();
		for (Department department : departments) {
			department.setEmployeeList(employeeMapper.findEmployeeByDepartmentId(department.getId()));
		}
		return departments;
	}

	@Override
	public Department fetchDepartmentById(int departmentId) {
		Department department = departmentMapper.fetchDepartmentById(departmentId);
		department.setEmployeeList(employeeMapper.findEmployeeByDepartmentId(department.getId()));
		return department;
	}

}
